package com.test.service;


import com.test.dao.ManagerOperatDao;
import com.test.dao.StuOperatDao;
import com.test.entity.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.persistence.criteria.CriteriaBuilder;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.util.Map;

@Service
public class ManagerOperatService {
    @Autowired
    private ManagerOperatDao managerOperatDao;

    public List<TeaAllInfoDto> selectAlltea(TeaAllInfoDto teaAllInfoDto){
        List<TeaAllInfoDto> tealist =  managerOperatDao.selectAlltea(teaAllInfoDto);
        return tealist;
    }

    public List<CompAllInfoDto> selectAllcomp(CompAllInfoDto compAllInfoDto){
        List<CompAllInfoDto> tealist =  managerOperatDao.selectAllcomp(compAllInfoDto);
        return tealist;
    }



    public int disableUser(String u_acount){
        return managerOperatDao.disableUser(u_acount);
    }

    public int enableUser(String u_acount){
        return managerOperatDao.enableUser(u_acount);
    }


    public List<TeaAllInfoDto> selectTeaByStuCode(String u_acount){
        List<TeaAllInfoDto> tealist =  managerOperatDao.selectTeaByStuCode(u_acount);
        return tealist;
    }

    public List<CompAllInfoDto> selectCompByCode(String u_acount){
        List<CompAllInfoDto> tealist =  managerOperatDao.selectCompByCode(u_acount);
        return tealist;
    }

    public List<Map<String,Object>> selectPeidata(){
        List<Map<String,Object>> peidatalist=  managerOperatDao.selectPeidata();
        return peidatalist;
    }

    public List<Map<String,Object>> SelectEmploymentRanking(){
        List<Map<String,Object>> peidatalist=  managerOperatDao.SelectEmploymentRanking();
        return peidatalist;
    }


    public List<Map<String,Object>> SelectEmploymentAddress(){
        List<Map<String,Object>> peidatalist=  managerOperatDao.SelectEmploymentAddress();
        return peidatalist;
    }


    public List<Map<String,Object>> SelectcollegeProportionPei(){
        List<Map<String,Object>> peidatalist=  managerOperatDao.SelectcollegeProportionPei();
        return peidatalist;
    }


    public List<Map<String,Object>> SelectcollegeJobProportionPei(){
        List<Map<String,Object>> peidatalist=  managerOperatDao.SelectcollegeJobProportionPei();
        return peidatalist;
    }


    public List<Map<String,Object>> SelectcollegeFurtherProportionPei(){
        List<Map<String,Object>> peidatalist=  managerOperatDao.SelectcollegeFurtherProportionPei();
        return peidatalist;
    }


    public int submitNewsPortal(NewsPortalDto newsPortalDto){
        int result=  managerOperatDao.submitNewsPortal(newsPortalDto);
        return result;
    }



    public List<NewsPortalDto> selectAllNewsPortal(String news_headline){
        List<NewsPortalDto> peidatalist=  managerOperatDao.selectAllNewsPortal(news_headline);

        for(int i=0;i<peidatalist.size();i++){
            Date date = peidatalist.get(i).getNews_releasetime();
            SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            String dateString = formatter.format(date);
            peidatalist.get(i).setNews_releasetimeStr(dateString);
        }

        return peidatalist;
    }


    public List<Map<String,Object>> selectAllemploymentRanking(){
        List<Map<String,Object>> peidatalist=  managerOperatDao.selectAllemploymentRanking();
        return peidatalist;
    }


    public List<ReleaseJobDto> selectAllentreprisesNews(String recruit_name){
        List<ReleaseJobDto> peidatalist=  managerOperatDao.selectAllentreprisesNews();
        for(int i=0;i<peidatalist.size();i++){
            Date date = peidatalist.get(i).getRecruit_updatetime();
            SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            String dateString = formatter.format(date);
            peidatalist.get(i).setRecruit_updatetimeStr(dateString);
        }
        if(recruit_name!=null&&!"".equals(recruit_name)){
            for(int j=0;j<peidatalist.size();j++){



                if(recruit_name.contains(peidatalist.get(j).getRecruit_updatetimeStr())&&recruit_name.contains(peidatalist.get(j).getRecruit_name())){
                    Date recruit_updatetime  = peidatalist.get(j).getRecruit_updatetime();
                     peidatalist = managerOperatDao.selectAllentreprisesNewsByName(peidatalist.get(j).getRecruit_updatetimeStr(),peidatalist.get(j).getRecruit_name());
                    for(int k = 0;k<peidatalist.size();k++){
                        Date date = peidatalist.get(k).getRecruit_updatetime();
                        SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
                        String dateString = formatter.format(date);
                        peidatalist.get(k).setRecruit_updatetimeStr(dateString);

                    }
                }


            }

        }



        return peidatalist;
    }




}
